#include #include #include #include #include #define TFT_GREY 0x5AEB TFT_eSPI tft = TFT_eSPI(); TFT_eSprite spr = TFT_eSprite(&tft); #define PIN_IN1 16 #define PIN_IN2 17 RotaryEncoder encoder(PIN_IN1, PIN_IN2, RotaryEncoder::LatchMode::TWO03); #define color1 0xC638 #define color2 0xC638 int value=980; int minimal=880; int maximal=1080; int strength=0; String sta[6]={"Ant.5","92.0","Metro","94.8","Super","97.0"}; float freq=0.00; TEA5767 radio = TEA5767(); bool muted=0; int deb=0; uint32_t targetTime = 0; // for next 1 second timeout static uint8_t conv2d(const char* p); // Forward declaration needed for IDE 1.6.x uint8_t hh = conv2d(__TIME__), mm = conv2d(__TIME__ + 3), ss = conv2d(__TIME__ + 6); // Get H, M, S from compile time byte omm = 99, oss = 99; byte xcolon = 0, xsecs = 0; unsigned int colour = 0; void setup() { tft.begin(); tft.writecommand(0x11); tft.setRotation(1); tft.fillScreen(TFT_BLACK); tft.setTextSize(1); tft.setTextColor(TFT_WHITE, TFT_BLACK); targetTime = millis() + 1000; pinMode(0, INPUT_PULLUP); Wire.begin(21,22); spr.createSprite(320,170); spr.setTextDatum(4); spr.setSwapBytes(true); spr.setFreeFont(&Orbitron_Light_24); spr.setTextColor(color1,TFT_BLACK); drawSprite(); } void readEncoder() { static int pos = 0; encoder.tick(); if(digitalRead(0)==0){ if(deb==0){ deb=1; muted=!muted; radio.setMuted(muted); drawSprite(); delay(200); } }else deb=0; int newPos = encoder.getPosition(); if (pos != newPos) { if(newPos>pos) value=value-1; if(newPos 59) { // Check for roll-over mm = 0; hh++; // Advance hour if (hh > 23) { // Check for 24hr roll-over (could roll-over on 13) hh = 0; // 0 for 24 hour clock, set to 1 for 12 hour clock } } } // Update digital time int xpos = 110; int ypos = 183; // Top left corner ot clock text, about half way down int ysecs = ypos; // + 24; if (omm != mm) { // Redraw hours and minutes time every minute omm = mm; // Draw hours and minutes if (hh < 10) xpos += tft.drawChar('0', xpos, ypos, 6); // Add hours leading zero for 24 hr clock xpos += tft.drawNumber(hh, xpos, ypos, 6); // Draw hours xcolon = xpos; // Save colon coord for later to flash on/off later xpos += tft.drawChar(':', xpos, ypos - 8, 6); if (mm < 10) xpos += tft.drawChar('0', xpos, ypos, 6); // Add minutes leading zero xpos += tft.drawNumber(mm, xpos, ypos, 6); // Draw minutes xsecs = xpos; // Sae seconds 'x' position for later display updates } if (oss != ss) { // Redraw seconds time every second oss = ss; xpos = xsecs; if (ss % 2) { // Flash the colons on/off tft.setTextColor(0x39C4, TFT_BLACK); // Set colour to grey to dim colon tft.drawChar(':', xcolon, ypos, 6); // Hour:minute colon xpos += tft.drawChar(':', xsecs, ysecs, 6); // Seconds colon tft.setTextColor(TFT_WHITE, TFT_BLACK); // Set colour back to yellow } else { tft.drawChar(':', xcolon, ypos, 6); // Hour:minute colon xpos += tft.drawChar(':', xsecs, ysecs, 6); // Seconds colon } //Draw seconds if (ss < 10) xpos += tft.drawChar('0', xpos, ysecs, 6); // Add leading zero tft.drawNumber(ss, xpos, ysecs, 6); // Draw seconds } } } // Function to extract numbers from compile time string static uint8_t conv2d(const char* p) { uint8_t v = 0; if ('0' <= *p && *p <= '9') v = *p - '0'; return 10 * v + *++p - '0'; }